package com.ww.word.ui;

import net.youmi.android.AdManager;
import net.youmi.android.offers.OffersManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.ww.core.activity.MySplashActivity;
import com.ww.core.util.CoreSharedPreferencesHelper;
import com.ww.core.util.DeviceUtil;
import com.ww.core.widget.dialog.RememberDialog;
import com.ww.word.R;
import com.ww.word.ui.menu.MenuActivity;
import com.ww.word.uti.JMPManager;

/**
 * @since 
 * @version 2013-12-19
 * @author wangwei
 */
public class SplashActivity extends MySplashActivity {
	private final String FS_ID = "2158065";
	private static boolean openAdView = true;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);

		JMPManager manager = new JMPManager();
		manager.startService(this, 1);
		
		AdManager.getInstance(this).init("a3bd3abb0b7f7e13", "ea2143aa83839345", false);
		// 如果使用积分广告，请务必调用积分广告的初始化接口:
		OffersManager.getInstance(this).onAppLaunch();

		CoreSharedPreferencesHelper h = new CoreSharedPreferencesHelper(SplashActivity.this);
		String str = h.getValue("num");
		if (str == null) {
			h.setValue("num", "5");
		}

		checkNet();
	}

	private void checkNet() {
		if (DeviceUtil.checkNet(this)) {
			to();
		} else {
			CoreSharedPreferencesHelper h = new CoreSharedPreferencesHelper(SplashActivity.this);
			String bool = h.getValue("word_show");
			if (bool == null || "false".equals(bool)) {
				final RememberDialog alertDialog = new RememberDialog(this);
				alertDialog.show("提示", "没有网络将不能进行拼音朗读，是否进行网络设置", new OnClickListener() {
					@Override
					public void onClick(View v) {
						alertDialog.cancel();
						startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 1);
					}
				}, new OnClickListener() {
					@Override
					public void onClick(View v) {
						alertDialog.cancel();
						to();
					}
				}, "word_show");
			} else {
				to();
			}
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) { // resultCode为回传的标记，我在B中回传的是RESULT_OK
		case 1:
			to();
			break;
		}
	}

	private void to() {
		gotoMain(FS_ID, Constants.DATABASE_PATH, Constants.DATABASE_NAME, R.raw.daydayup, new Intent(
				getApplicationContext(), MenuActivity.class), openAdView);
	}

}
